import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'
Vue.use(Router)

const routerList = []
function registerRouter(router) {
  router.keys().forEach(key => {
    routerList.push(router(key).default)
  })
}
registerRouter(require.context('./modules', true, /\.router\.js/))
export const constantRoutes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/home',
    name: 'Home',
    component: Layout,
    redirect: '/home/home',
    meta: { title: '首页管理' },
    children: [
      {
        path: 'home',
        component: () => import('@/views/home/index'),
        name: 'Home',
        meta: { title: '首页' },
        hidden: true
      }
    ]
  }
]
export const asyncRoutes = [
  ...routerList,
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

export default new Router({
  mode: 'history',
  routes: constantRoutes
})
